﻿using System;
using System.Diagnostics.Contracts;
using System.Linq;
using OpenWaves.ActivityFeed.NHibernate;

namespace OpenWaves.ActivityFeed.Web.NHibernate
{
    public class PersonalActivityFeedBuilder : NHibernateActivityFeedBuilder
    {
        protected readonly string SubscriberId;

        public PersonalActivityFeedBuilder(string subscriberId, IActivityFeedService activityFeedService, IUpdateDtoBuilder updateDtoBuilder)
            : base(activityFeedService, updateDtoBuilder)
        {
            this.SubscriberId = subscriberId;
        }

        protected override IQueryable<Update> FilterUpdates(IQueryable<Update> updates)
        {
            Contract.Requires<ArgumentNullException>(updates != null);

            var subscriber = this.ActivityFeedService.GetSubscriber(this.SubscriberId);
            return base.FilterUpdates(updates.ForSubscriber(subscriber));
        }
    }
}